package com.lams.action.corpus;

import java.util.HashMap;
import java.util.Map;

import com.lams.action.SubAction;
import com.lams.service.corpus.ISearchFacade;
import com.lams.util.ResultEntity;

public class Search extends SubAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6816348068245108006L;
	private String query;
	private String articleId;
	private int leftNum;
	private int rightNum;
	private String ARTICLE_NAME;
	private String AUTHOR;
	private String CONTENT;
	private String ARTICLE_ID;
	private Map params = new HashMap();
	private String[] keys;// 查询关键字列表
	private ISearchFacade sf;
	public String search() {
		ResultEntity result = sf.search(this.getStart(), this.getLimit(), params);
		result.setSuccess(true);
		result.setMessage(query);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}
	public String queryArticle(){
		ResultEntity result = sf.queryArticle(params, this.getStart(), this.getLimit());
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public String addOrUpdateArticle(){
//		HttpServletRequest request = ServletActionContext.getRequest();
//		List list = new ArrayList();
		ResultEntity result = sf.addOrUpdateArticle(params, this.getARTICLE_ID()==null||"".equals(this.getARTICLE_ID())||"-1".equals(this.getARTICLE_ID())?"add":"update");
		//result.setData(list);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		query = query.trim();
		if (query.indexOf(" ") == -1) {
			this.keys = new String[]{query};
		} else {
			String q = query.replaceFirst(" ", "\\|");
			String[] temp = q.split("\\|");
			this.keys = new String[temp.length];
			for (int i = 0; i < temp.length; i++) {
				keys[i] = temp[i].trim();
			}
		}
		this.query = query;
		params.put("KEY", this.keys);
	}
	public String getArticleId() {
		return articleId;
	}
	public void setArticleId(String articleId) {
		this.articleId = articleId;
		params.put("articleId", articleId);
	}
	public int getLeftNum() {
		return leftNum;
	}

	public void setLeftNum(int leftNum) {
		this.leftNum = leftNum;
		params.put("LEFTNUM", this.leftNum);
	}

	public int getRightNum() {
		return rightNum;
	}

	public void setRightNum(int rightNum) {
		this.rightNum = rightNum;
		params.put("RIGHTNUM", this.rightNum);
	}

	public ISearchFacade getSf() {
		return sf;
	}

	public void setSf(ISearchFacade sf) {
		this.sf = sf;
	}
	public String getARTICLE_NAME() {
		return ARTICLE_NAME;
	}
	public void setARTICLE_NAME(String aRTICLE_NAME) {
		ARTICLE_NAME = aRTICLE_NAME;
		params.put("ARTICLE_NAME", ARTICLE_NAME);
	}
	public String getAUTHOR() {
		return AUTHOR;
	}
	public void setAUTHOR(String aUTHOR) {
		AUTHOR = aUTHOR;
		params.put("AUTHOR", AUTHOR);
	}
	public String getCONTENT() {
		return CONTENT;
	}
	public void setCONTENT(String cONTENT) {
		CONTENT = cONTENT;
		params.put("CONTENT", CONTENT);
	}
	public String getARTICLE_ID() {
		return ARTICLE_ID;
	}
	public void setARTICLE_ID(String aRTICLE_ID) {
		ARTICLE_ID = aRTICLE_ID;
		params.put("ARTICLE_ID", ARTICLE_ID);
	}
	
}
